package com.example.demo.config;

import com.example.demo.interceptor.AdminInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Admin拦截器的配置
 */
@Configuration
public class AdminInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private AdminInterceptor adminInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        System.out.println("-----------addInterceptors-----------");
        /**
         * 拦截器按照顺序执行
         *addPathPatterns 用于添加拦截规则
         *excludePathPatterns 用于排除拦截
         */
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/back/*")   // 拦截的路径
                .excludePathPatterns("/back/login", "/back/enter"); // 排除拦截的路径
    }

}
